﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using RTGS.Library.Entities.Rtgs;
using RTGS.Library.DataAccess.Rtgs;
using System.Configuration;
using System.Data;
using RTGS.Library.Report;

namespace RTGS.Web.form.rtgs
{

public partial class form_rtgs_record_detail_i_cancel_form : BasePage
{
        private string id = string.Empty;
        private stpRecordDetailIRepo roleDal = new stpRecordDetailIRepo(ConfigurationManager.ConnectionStrings["Rtgs"].ConnectionString);
        ReportSptDetailRecordO reportDal = new ReportSptDetailRecordO(ConfigurationManager.ConnectionStrings["Rtgs"].ConnectionString);
        private trntRepo trntrepo = new trntRepo(ConfigurationManager.ConnectionStrings["Rtgs"].ConnectionString);
        private stpReasonRepo reasonRepo = new stpReasonRepo(ConfigurationManager.ConnectionStrings["Rtgs"].ConnectionString);

        protected void Page_Load(object sender, EventArgs e)
        {

            try
            {
                DataTable dt = reportDal.GetMember();

                ddlDebitParticipant.Items.Clear();
                foreach (DataRow dr in dt.Rows)
                {
                    ddlDebitParticipant.Items.Add(new ListItem(dr["memcde"].ToString().Trim(), dr["memcde"].ToString().Trim()));
                }

                ddlDebitParticipant.Items.Insert(0, new ListItem("---pilih data--", string.Empty));

                ddlCreditParticipant.Items.Clear();
                foreach (DataRow dr in dt.Rows)
                {
                    ddlCreditParticipant.Items.Add(new ListItem(dr["memname"].ToString().Trim(), dr["memcde"].ToString().Trim()));
                }

                ddlCreditParticipant.Items.Insert(0, new ListItem("---pilih data--", string.Empty));


                List<trnt> listtrnt = trntrepo.GetList();
                foreach (var item in listtrnt)
                {
                    ddlTrn.Items.Add(new ListItem(item.trn, item.trndesc));
                }

                ddlTrn.Items.Insert(0, new ListItem("---Pilih Data---", string.Empty));

                List<stpReason> listReason = reasonRepo.GetList();

                foreach (var item in listReason)
                {
                    ddlReason.Items.Add(new ListItem(item.reasonid + " - " + item.reasondesc, item.reasonid.Trim()));
                }

                ddlReason.Items.Insert(0, new ListItem("---Pilih Data---", string.Empty));


                if (Request.Params["Id"] != null)
                {
                    id = HttpUtility.HtmlEncode(Convert.ToString(Request.Params["Id"]));
                }

                if (!Page.IsPostBack)
                {


                    if (id.Trim().Length > 0) // Edit an existing item
                    {
                        stpRecordDetailI obj = roleDal.GetById(id);
                        if (obj != null)
                        {
                            hfID.Value = id.ToString();

                            //GROUP TRN
                            //txtTrn.Text = obj.recordDetailItrTrn;

                            if (obj.recordDetailItrTrn != "")
                            {
                                if (ddlTrn.Items.Count > 0)
                                {
                                    for (int i = 0; i < ddlTrn.Items.Count; i++)
                                    {
                                        if (ddlTrn.Items[i].ToString().Trim() == obj.recordDetailItrTrn.Trim())
                                        {

                                            ddlTrn.Items.FindByText(obj.recordDetailItrTrn).Selected = true;
                                        }
                                    }
                                }

                                trnt data = trntrepo.GetById(obj.recordDetailItrTrn);

                                txtTrnDesc.Text = data.trndesc;
                            }

                            txtRelatedTrn.Text = obj.recordDetailItrRelatedtrn;

                            //GROUP AMOUNT
                            if (obj.recordDetailItrAmount != null && obj.recordDetailItrAmount != "")
                                txtAmount.Text = Convert.ToDecimal(obj.recordDetailItrAmount).ToString("#,###.00");
                            txtCurrency.Text = obj.recordDetailIstCurrency.Trim();
                            txtBussinesDay.Text = obj.recordDetailItrValuedate.Trim();



                            //GROUP DEBIT PARTICIPANT
                            //txtDebitParticipant.Text = obj.recordDetailIstFromaccountnumber.Trim();
                            txtAccountDebitParticipant.Text = obj.recordDetailIstFromaccountnumber.Trim();

                            //GROUP CREDIT PARTICIPANT
                            //txtCreditParticipant.Text = obj.recordDetailIstToaccountnumber.Trim();
                            txtAccountCreditParticipant.Text = obj.recordDetailIstToaccountnumber.Trim();

                            //GROUP DEBIT PARTICIPANTS CLIENT
                            txtDebitParticipantsClient.Text = obj.recordDetailIstOriginatingname.Trim();
                            txtAccountDebitParticipantsClient.Text = obj.recordDetailIstOriginatingnumber.Trim();

                            //GROUP CREDIT PARTICIPANTS CLIENT
                            txtCreditParticipantsClient.Text = obj.recordDetailIstUltimatebenefname.Trim();
                            txtAccountParticipantsClient.Text = obj.recordDetailIstUltimatebenefaccount.Trim();

                            //GROUP DETAIL
                            //txtRemitanceInformation.Text = obj.recordDetailIstMemberinfo.Trim();
                            txtRemitanceInformation.Text = obj.recordDetailIstPaymentdetails.Trim(); //obj.recordDetailIstMemberinfo.Trim();
                            txtDetailOfCharges.Text = obj.recordDetailItrRecordtype.Trim();
                            txtTransactionSubTypeCode.Text = obj.recordDetailItrTransactioncode.Trim();
                            txtSender.Text = obj.recordDetailIstMemberinfo.Trim();//obj.recordDetailIstPaymentdetails.Trim();
                            //txtSender.Text = obj.recordDetailIstPaymentdetails.Trim();


                            //GROUP PRIORITY

                            if (obj.recordDetailItrFrommember != null && obj.recordDetailItrFrommember != "")
                                ddlDebitParticipant.Items.FindByValue(obj.recordDetailItrFrommember.Trim()).Selected = true;
                            if (obj.recordDetailItrTomember != null && obj.recordDetailItrTomember != "")
                                ddlCreditParticipant.Items.FindByValue(obj.recordDetailItrTomember.Trim()).Selected = true;

                            txtNameCodeCredit.Text = obj.recordDetailIstToaccountname;
                            txtNameCodeDebit.Text = obj.recordDetailIstFromaccountname;
                            
                            if(obj.recordDetailIstRsncde!=null&&obj.recordDetailIstRsncde!="")
                                ddlReason.Items.FindByValue(obj.recordDetailIstRsncde.Trim()).Selected = true;

                            //txtReason.Text = obj.recordDetailIstRsncde;


                            //if (Request.Params["typeIncoming"].ToString() == "repair")
                            //{

                            //    txtReason.Font.Bold = true;
                            //    txtReason.ForeColor = System.Drawing.Color.Red;

                            //    if (obj.recordDetailIstRsncde.Trim() == "011")
                            //    {

                            //        txtCreditParticipantsClient.ReadOnly = false;
                            //        txtAccountParticipantsClient.ReadOnly = false;
                            //        txtReason.Text = "011 :  ultimateBeneaccount not match with account master";
                            //    }

                            //    if (obj.recordDetailIstRsncde.Trim() == "012")
                            //    {

                            //        txtDebitParticipantsClient.ReadOnly = false;
                            //        txtAccountDebitParticipantsClient.ReadOnly = false;
                            //        txtReason.Text = "012 : ultimateBeneName Not match with account master";
                            //    }


                            //}

                        }
                    }
                }

            }
            catch (Exception ex)
            {

            }
        }

}

}